package ocean.chinacraft.common.entity.projectile;

import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.projectile.ThrowableEntity;
import net.minecraft.network.IPacket;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.World;
import net.minecraftforge.fml.network.NetworkHooks;
import ocean.chinacraft.common.ModEntityTypes;
import ocean.chinacraft.common.world.item.ModSounds;

/**
 * 鞭炮Entity
 *
 * @author zhang
 * @since 2021/12/25
 */
public class FirecrackerEntity extends ThrowableEntity {

    public FirecrackerEntity(EntityType<? extends FirecrackerEntity> entityType, World world) {
        super(entityType, world);
    }

    public FirecrackerEntity(World world, LivingEntity livingEntity) {
        super(ModEntityTypes.FIRE_CRACKER.get(), livingEntity, world);
    }

    @Override
    protected void defineSynchedData() {

    }

    @Override
    protected void onHit(RayTraceResult result) {
        Vector3d location = result.getLocation();
        level.playSound(null, location.x, location.y, location.z, ModSounds.FIRE_CRACKER.get(),
                SoundCategory.VOICE, 1F, 1F);
    }

    @Override
    public IPacket<?> getAddEntityPacket() {
        return NetworkHooks.getEntitySpawningPacket(this);
    }
}
